//
//  BaseNavigationViewController.swift
//  CreateChina
//
//  Created by 贾培军 on 2020/4/15.
//  Copyright © 2020 贾培军. All rights reserved.
//

import UIKit

open class SWBaseNavigationViewController: UINavigationController, UINavigationControllerDelegate, UIGestureRecognizerDelegate{

    public func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
        let vc = viewController as? SWBaseViewController
        navigationBar.setBackgroundImage(.image(.white), for: .default)
//        if viewController.responds(to: sel){
        self.setNavigationBarHidden(vc?.needHideNavigationBar ?? true, animated: true)
//        }else{
//            self.setNavigationBarHidden(true, animated: true)
//        }
    }
    
    func fullScreenPop() {
        guard let systemGes = interactivePopGestureRecognizer else { return }
        
        // 获取系统手势添加的view
        guard let gesView = systemGes.view else { return }
        
        //从Targets 取出 Target
        let targets = systemGes.value(forKey: "_targets") as? [NSObject]
        guard let targetObjc = targets?.first else { return }
        guard let target = targetObjc.value(forKey: "target") else { return }
        //方法名称获取 Action
        let action = Selector(("handleNavigationTransition:"))
        

        let panGes = UIPanGestureRecognizer()
        gesView.addGestureRecognizer(panGes)
        panGes.addTarget(target, action: action)
    }
    
    open override func viewDidLoad() {
        super.viewDidLoad()
        weak var weakSelf = self
        delegate = weakSelf
        interactivePopGestureRecognizer?.delegate = weakSelf
        fullScreenPop()
        view.backgroundColor = .white
        // Do any additional setup after loading the view.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destination.
        // Pass the selected object to the new view controller.
    }
    */

}
